<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" name="viewport" content="width-device-width,initial-scale=1">
    <script src="/js/jquery.min.js"></script>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/css/formcss.css" >
    <title>长流注册</title>
    <script>
        function check(){
            let password = document.getElementById("pwd").value;
            let repsword = document.getElementById("pwd1").value;
            let sign = false;
            if(password === ''){
                alert('密码不能为空');
                return sign;
            }
            if(password != repsword) {
                alert("两次密码不同，请重新输入");
                return sign;
            }
            $.ajax({
                type: 'POST',
                contentType: 'application/json;charset=utf-8',
                url: '/home/register/' + $("input[name=name]").val()+"/"+ $("input[name=pwd]").val(),
                dataType: 'json',
                success: function (data) {
                    if (data['message']=="已存在")
                        alert("注册失败，已存在该用户名");
                    else if(data['message']=="注册成功") {
                        alert("注册成功");
                        $(location).attr("href","/");
                    }
                },
                error: function (err) {
                    alert(err);
                }
            })
        }
    </script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-offset-3 col-md-6">
            <form class="form-horizontal" action="/register" method="post">
                <span class="heading">用户注册</span>
                <div class="form-group">
                    <input type="text" class="form-control" name="name" id="name"  placeholder="用户名">
                    <i class="fa fa-user"></i>
                </div>
                <div class="form-group help">
                    <input type="password" class="form-control" name="pwd" id="pwd" placeholder="密　码">
                    <i class="fa fa-lock"></i>
                    <a href="#" class="fa fa-question-circle"></a>
                </div>
                <div class="form-group help">
                    <input type="password" class="form-control" name="pwd1" id="pwd1" placeholder="确认密码">
                    <i class="fa fa-lock"></i>
                    <a href="#" class="fa fa-question-circle"></a>
                </div>
                <div class="form-group">
                    <button type="button" class="btn btn-default"  onclick="check()">注册</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>